<?php
namespace app\index\controller;
use \app\index\model as indexModel;
use \app\api\model as apiModel;
class Index
{
    public function index()
    {
        $api = new \app\api\controller\Index();

        $focus = $api->getNews('focus',0,6);
        return view('index',['focus'=>$focus]);
    }

    public function art($id=''){

        if(!is_numeric($id)){
            return '';
        }

        $news = new indexModel\EcmsNews();

        $arc = $news ->content($id);

        //如果是外部链接则直接跳转
        if (1 == $arc[0]['isurl']) {
            self_header($arc[0]['titleurl']);
        }

        $arc[0]['newstext'] = stripslashes($arc[0]['newstext']);
        $arc[0]['title'] = str_convert($arc[0]['title']);
        $arc[0]['smalltext'] = str_convert($arc[0]['smalltext']);

        $str = '<img src="'.\think\Config::get('lazyloadimg').'" data-echo="$2">';
        $arc[0]['newstext'] = preg_replace("/<img[^>]+(src=['|\"]*([^'\"]+)['|\"]*)[^>]*>/",$str,$arc[0]['newstext']);

        $good = new apiModel\EcmsNews();
        $goods = $good->getGoodList(5,",smalltext,befrom");
        foreach($goods as $k => $val){

            $goods[$k]['title'] = str_convert($val['title']);
            $goods[$k]['newstime'] = date("Y-m-d",$val['newstime']);
            //去掉开头双字节空格
            $goods[$k]['smalltext'] = str_convert($val['smalltext']);
            $goods[$k]['befrom'] = empty($val['befrom']) ? "中国社区网" : $val['befrom'];
        }

        return view('art',['arc'=>$arc[0],'goods'=>$goods]);


    }

    public function artList($id=''){

        if(!is_numeric($id)){
            return false;
        }

        $news = new indexModel\EcmsNews();

        $arc = $news ->content($id);

        dump($arc);
    }
}
